// 设置主题UI组件

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:my_first_app/utils/theme_provider.dart';
import 'package:my_first_app/utils/app_logger.dart';

class ComponentTheme extends StatelessWidget {
  ComponentTheme({super.key});
  final logger = AppLogger();

  @override
  Widget build(BuildContext context) {
    final themeProvider = Provider.of<ThemeProvider>(context);

    return ElevatedButton(
        onPressed: () {
          Provider.of<ThemeProvider>(context, listen: false).toggleTheme();
          logger.info('用户设置模式，当前是否为暗色模式 -> ${themeProvider.isDarkMode}');
        },
      child: Text(themeProvider.isDarkMode ? '切换为亮色模式' : '切换为黑暗模式'),
    );
  }
}